package com.itheima.threadmethod3;

public class Test {
    public static void main(String[] args) {

        //线程的join()方法：线程插队，插队线程执行完毕后，再执行当前线程
        Thread t1 = new MyThread1();
        t1.start();

        for (int i = 1; i < 5; i++) {
            System.out.println(Thread.currentThread().getName() + "主线程输出：" + i);

            if (i == 2) {
                try {
                    t1.join();      //插队，t1线程执行完毕后，再执行当前线程
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }
}

class MyThread1 extends Thread {
    @Override
    public void run() {
        for (int i = 1; i < 5; i++) {
            System.out.println(Thread.currentThread().getName() + "子线程输出：" + i);
        }
    }
}
